package me.minicoral.action;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import me.minicoral.service.CommentService;
import me.minicoral.service.impl.CommentServiceImpl;

import com.opensymphony.xwork2.ActionSupport;

public class Comment extends ActionSupport
{

	private static final long serialVersionUID = 1L;

	private String cid;
	private String uuid;
	private String bid;
	private String ccomment;
	private Date ccommenttime;

	public String getCid()
	{
		return cid;
	}

	public void setCid(String cid)
	{
		this.cid = cid;
	}

	public String getUuid()
	{
		return uuid;
	}

	public void setUuid(String uuid)
	{
		this.uuid = uuid;
	}

	public String getBid()
	{
		return bid;
	}

	public void setBid(String bid)
	{
		this.bid = bid;
	}

	public String getCcomment()
	{
		return ccomment;
	}

	public void setCcomment(String ccomment)
	{
		this.ccomment = ccomment;
	}

	public Date getCcommenttime()
	{
		return ccommenttime;
	}

	public void setCcommenttime(Date ccommenttime)
	{
		this.ccommenttime = ccommenttime;
	}

	@Override
	public String toString()
	{
		return "Comment [cid=" + cid + ", uuid=" + uuid + ", bid=" + bid
				+ ", ccomment=" + ccomment + ", ccommenttime=" + ccommenttime
				+ "]";
	}

	Map<Object, Object> dataMap = new HashMap<Object, Object>();

	public Map<Object, Object> getDataMap()
	{
		return dataMap;
	}

	private CommentService s = new CommentServiceImpl();

	public String addComment()
	{
		dataMap.clear();
		dataMap.put("status", false);
		dataMap.put("message", "评论失败，请检查您的网络。");
		setCid(UUID.randomUUID().toString());
		System.out.println(this);
		int i = 0;
		if (uuid != null && bid != null && ccomment != null)
		{
			i = s.addComment(this);
		}
		System.out.println(i);
		if (i == 1)
		{
			dataMap.put("status", true);
			dataMap.put("message", "评论成功。");
		}
		return SUCCESS;
	}
	
	public String showCommentByBid()
	{
		dataMap.clear();
		dataMap.put("status", false);
		dataMap.put("message", "拉取评论失败，请检查您的网络。");
		List<Comment> list = s.showCommentByBid(bid);
		return SUCCESS;
	}
	
	public String getCommentCount()
	{
		return SUCCESS;
	}
}
